
<!DOCTYPE HTML>
<html lang="en" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.2 请求路由 · smartboot 中文指南</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="file_upload.html" />
    
    
    <link rel="prev" href="./" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    关于smartboot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    smart-socket 使用手册
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../smart-socket/">
            
                <a href="../../smart-socket/">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" >
            
                <span>
            
                    
                    第一章 smart-socket开发指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../../smart-socket/chapter-1/2.1-基础应用/">
            
                <a href="../../smart-socket/chapter-1/2.1-基础应用/">
            
                    
                    1.1 快速上手
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="../../smart-socket/chapter-1/2.2-Spring集成/">
            
                <a href="../../smart-socket/chapter-1/2.2-Spring集成/">
            
                    
                    1.2 Spring集成smart-socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.3" data-path="../../smart-socket/chapter-1/SUMMARY.html">
            
                <a href="../../smart-socket/chapter-1/SUMMARY.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../smart-socket/chapter-2/">
            
                <a href="../../smart-socket/chapter-2/">
            
                    
                    第二章 源码解析
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../../smart-socket/chapter-2/核心接口/">
            
                <a href="../../smart-socket/chapter-2/核心接口/">
            
                    
                    2.1 核心接口与状态机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../../smart-socket/chapter-2/服务端/">
            
                <a href="../../smart-socket/chapter-2/服务端/">
            
                    
                    2.2 服务端
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="../../smart-socket/chapter-2/客户端/">
            
                <a href="../../smart-socket/chapter-2/客户端/">
            
                    
                    2.3 客户端
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="../../smart-socket/chapter-2/AioSession/">
            
                <a href="../../smart-socket/chapter-2/AioSession/">
            
                    
                    2.4 会话AioSession
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="../../smart-socket/chapter-2/SUMMARY.html">
            
                <a href="../../smart-socket/chapter-2/SUMMARY.html">
            
                    
                    2.5 小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../smart-socket/chapter-3/">
            
                <a href="../../smart-socket/chapter-3/">
            
                    
                    第三章 通信协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="../../smart-socket/chapter-3/1-消息归类/">
            
                <a href="../../smart-socket/chapter-3/1-消息归类/">
            
                    
                    3.1 消息归类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="../../smart-socket/BLANK.html">
            
                <a href="../../smart-socket/BLANK.html">
            
                    
                    3.2 半包/粘包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="../../smart-socket/BLANK.html">
            
                <a href="../../smart-socket/BLANK.html">
            
                    
                    3.3 Http消息解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.4" data-path="../../smart-socket/BLANK.html">
            
                <a href="../../smart-socket/BLANK.html">
            
                    
                    3.4 RPC消息解析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../../smart-socket/chapter-5/">
            
                <a href="../../smart-socket/chapter-5/">
            
                    
                    第四章 内存池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../../smart-socket/chapter-6/">
            
                <a href="../../smart-socket/chapter-6/">
            
                    
                    第五章 未来规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../../smart-socket/end/">
            
                <a href="../../smart-socket/end/">
            
                    
                    附录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    smart-http 实战手册
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../">
            
                <a href="../">
            
                    
                    关于smart-http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" >
            
                <span>
            
                    
                    第一章 smart-http开发指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="./">
            
                <a href="./">
            
                    
                    1.1 快速上手
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.2.2" data-path="http_route.html">
            
                <a href="http_route.html">
            
                    
                    1.2 请求路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.3" data-path="file_upload.html">
            
                <a href="file_upload.html">
            
                    
                    1.3 文件上传/下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.4" data-path="websocket.html">
            
                <a href="websocket.html">
            
                    
                    1.4 WebSocket
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    技术分享
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../share/rpc/smart-socket-rpc.html">
            
                <a href="../../share/rpc/smart-socket-rpc.html">
            
                    
                    smart-socket实现RPC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../share/firstfit/readme.html">
            
                <a href="../../share/firstfit/readme.html">
            
                    
                    内存管理-首次适应算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../share/thread/readme.html">
            
                <a href="../../share/thread/readme.html">
            
                    
                    Thread知多少
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../donation.html">
            
                <a href="../../donation.html">
            
                    
                    关于捐赠
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >1.2 请求路由</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x8BF7;&#x6C42;&#x8DEF;&#x7531;">&#x8BF7;&#x6C42;&#x8DEF;&#x7531;</h2>
<p>&#x719F;&#x6089; Servlet &#x6216;&#x8005; Spring MVC &#x5F00;&#x53D1;&#x7684;&#x4EBA;&#x5E94;&#x8BE5;&#x5BF9;&#x8FD9;&#x4E2A;&#x4E0D;&#x964C;&#x751F;&#xFF0C;
&#x524D;&#x7AEF;&#x8BF7;&#x6C42;&#x7684;&#x4E0D;&#x540C;&#x63A5;&#x53E3;&#xFF0C;&#x9700;&#x8981;&#x8DEF;&#x7531;&#x5230;&#x4E0D;&#x540C; Servlet &#x6216;&#x8005; Controller &#x4E2D;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x3002;</p>
<p>smart-http &#x4E5F;&#x63D0;&#x4F9B;&#x4E86;&#x8BF7;&#x6C42;&#x8DEF;&#x7531;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x4F7F;&#x7528;&#x65F6;&#x9700;&#x8981;&#x7528;&#x5230;<code>HttpRouteHandle</code>&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HttpRouteDemo</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">//1. &#x5B9E;&#x4F8B;&#x5316;&#x8DEF;&#x7531;Handle</span>
        HttpRouteHandle routeHandle = <span class="hljs-keyword">new</span> HttpRouteHandle();

        <span class="hljs-comment">//2. &#x6307;&#x5B9A;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#x4EE5;&#x53CA;&#x8BF7;&#x6C42;&#x7684;&#x5904;&#x7406;&#x5B9E;&#x73B0;</span>
        routeHandle.route(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-keyword">new</span> HttpHandle() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doHandle</span><span class="hljs-params">(HttpRequest request, HttpResponse response)</span> <span class="hljs-keyword">throws</span> IOException </span>{
                response.write(<span class="hljs-string">&quot;smart-http&quot;</span>.getBytes());
            }
        }).route(<span class="hljs-string">&quot;/test1&quot;</span>, <span class="hljs-keyword">new</span> HttpHandle() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doHandle</span><span class="hljs-params">(HttpRequest request, HttpResponse response)</span> <span class="hljs-keyword">throws</span> IOException </span>{
                response.write((<span class="hljs-string">&quot;test1&quot;</span>).getBytes());
            }
        }).route(<span class="hljs-string">&quot;/test2&quot;</span>, <span class="hljs-keyword">new</span> HttpHandle() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doHandle</span><span class="hljs-params">(HttpRequest request, HttpResponse response)</span> <span class="hljs-keyword">throws</span> IOException </span>{
                response.write((<span class="hljs-string">&quot;test2&quot;</span>).getBytes());
            }
        });

        <span class="hljs-comment">// 3. &#x542F;&#x52A8;&#x670D;&#x52A1;</span>
        HttpBootstrap bootstrap = <span class="hljs-keyword">new</span> HttpBootstrap();
        bootstrap.pipeline().next(routeHandle);
        bootstrap.start();
    }
}
</code></pre>
<p>&#x5F53;&#x7136;&#xFF0C;&#x5982;&#x679C; smart-http &#x9ED8;&#x8BA4;&#x63D0;&#x4F9B;&#x7684;&#x8DEF;&#x7531;&#x7EC4;&#x4EF6;&#x6EE1;&#x8DB3;&#x4E0D;&#x4E86;&#x4F60;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x7528;&#x6237;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7EE7;&#x627F;<code>HttpHandle</code>&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x4E00;&#x5957;&#x8BF7;&#x6C42;&#x8DEF;&#x7531;&#x7B97;&#x6CD5;&#x3002; </p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; smartboot.org 2018 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-01 23:03:06
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: 1.1 快速上手">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="file_upload.html" class="navigation navigation-next " aria-label="Next page: 1.3 文件上传/下载">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.2 请求路由","level":"1.3.2.2","depth":3,"next":{"title":"1.3 文件上传/下载","level":"1.3.2.3","depth":3,"path":"smart-http/chapter-1/file_upload.md","ref":"smart-http/chapter-1/file_upload.md","articles":[]},"previous":{"title":"1.1 快速上手","level":"1.3.2.1","depth":3,"path":"smart-http/chapter-1/README.md","ref":"smart-http/chapter-1/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-sharing","search-plus","expandable-chapters-interactive","tbfed-pagefooter","github","github-buttons","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy smartboot.org 2018","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://github.com/smartboot/smart-socket"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"expandable-chapters-interactive":{},"github-buttons":{"buttons":[{"user":"smartboot","repo":"smart-socket","type":"star","size":"small","count":true}]},"edit-link":{"label":"Edit This Page","base":"https://gitee.com/smartboot/book/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"smartboot 中文指南","language":"en","gitbook":"*","description":"本文涵盖了smartboot下所有项目的技术手册"},"file":{"path":"smart-http/chapter-1/http_route.md","mtime":"2020-04-01T15:03:06.010Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2020-04-02T05:22:17.739Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

